Abstract
What went wrong in 2016? This data project seeks to document the rise of Donald Trump through the demographics and geography of the United States. We employ techniques in data visualization and machine learning in attempt to characterize, understand, and explain Donald Trump’s ascendance to the presidency.
The 2016 General Election for President of the United States was our very first general election in which we were able to vote. Many pundits, politicians, and citizens alike found the contest between Hillary Clinton and Donald Trump to be one of the most bitter presidential races in recent memory, and many more were surprised by the outcome.
Most pollsters and statisticians had Hillary Clinton maintaining a comfortable margin before the election. Yet, Donald Trump emerged victorious as the 45th President of the United States. Our goal is to try to explain why.
We have incorporated US Census demographic data, as well as employing comparisons between Donald Trump’s 2016 victory with Barack Obama’s 2012 re-election against Mitt Romney.
Below are primarily the visualizations generated from our analysis. They were created via leaflet and ggplot2 in R. Our 2012 election data was obtained from the Huffington Post, and our 2016 election data was sourced from Kaggle.
Code for the graphics is not included in chunks below. Please consult our Github for more information, including our original graphics and code.
Our analysis excludes Alaska and Hawaii as well as third-party candidates.
Let’s take a look at the 2016 electoral map, divided by county.

The gradient within the map represents the margin of victory, from 60% or greater margin of victory for Trump in red to 60% or more margin of victory for Clinton in blue.
Naturally, Clinton has a visible edge in more urban, coastal areas while Trump has an advantage in more rural areas.
We can clarify the win by county by removing the gradient.

Let’s check out a few interactive maps created with leaflet. Clinton narrowly won Virginia while Trump narrowly won Pennsylvania. Clicking on the county will give you its name, Trump’s margin of victory, as well as each candidate’s respective number of votes (and share of the vote).